//
//  BRInvitePopView.m
//  Kexu
//
//  Created by IOS on 2023/7/27.
//

#import "BRInvitePopView.h"
#import "BRInviteRewardView.h"
@interface BRInvitePopView ()
{
    CGFloat _content_h;
    UIView *_contentView;
    
    QMUILabel *_describeL;
    QMUILabel *_titleL;
    QMUILabel *_priceL1;
    QMUILabel *_priceL2;
    QMUIButton *_redeemBtn;

}


@end
@implementation BRInvitePopView

- (instancetype)init
{
    self = [super init];
    if (self) {
        _content_h = kSafeAreaBottomHeight + 364;
        [self setUI];
    }
    return self;
}

- (void)hidd  {
    [self endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self->_contentView.transform = CGAffineTransformMakeRotation(0);
    } completion:^(BOOL finished) {
        self.hidden =  YES;
    }];
}

- (void)show {
    self.hidden = NO;
    [UIView animateWithDuration:0.25 animations:^{
        self->_contentView.transform = CGAffineTransformMakeTranslation(0, -(self->_content_h));
    }];
}

#pragma mark - UI --
- (void)setUI {
    self.hidden = YES;
    self.backgroundColor = UIColorMakeWithRGBA(0, 0, 0, 0.38);
    
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, _content_h)];
    contentView.backgroundColor = UIColor.whiteColor;
    [self addSubview:contentView];
    [contentView  layoutIfNeeded];
    // 设置顶部圆角
    // 绘制圆角 需设置的圆角 使用"|"来组合
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:contentView.bounds byRoundingCorners:UIRectCornerTopLeft |
    UIRectCornerTopRight cornerRadii:CGSizeMake(30, 30)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];

    // 设置大小
    maskLayer.frame = contentView.bounds;

    // 设置图形样子
    maskLayer.path = maskPath.CGPath;
    contentView.layer.mask = maskLayer;
    _contentView = contentView;
    
    QMUIButton *backBtn = [[QMUIButton alloc] initWithFrame:CGRectMake(kScreenWidth - 58, 0, 44, 44)];
    [backBtn setBackgroundImage:UIImageMake(@"arrow_close_gray44") forState:UIControlStateNormal];
    [contentView addSubview:backBtn];
//    _closeBtn = backBtn;
    [backBtn addTarget:self action:@selector(hidd) forControlEvents:UIControlEventTouchUpInside];
    
    QMUILabel *titleL = [BRToolsView br_label:Localized(@"invite_aboutReferral") textColor:kColorTitle font:[UIFont fontS:17] textAlignment:NSTextAlignmentCenter];
    [contentView addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.centerY.equalTo(backBtn.mas_centerY).offset(10);
    }];
    // ------------邀请规则----------------
    self.titleL = [BRToolsView br_label:Localized(@"invite_ruleText") textColor:kColorTitle font:[UIFont fontB:15] textAlignment:NSTextAlignmentLeft];
    self.titleL.numberOfLines = 0;
    [contentView addSubview:self.titleL];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(64);
        make.left.offset(20);
        make.right.offset(-20);
    }];
    self.textL = [BRToolsView br_label:@"--" textColor:kColorTitle font:[UIFont fontM:14] textAlignment:NSTextAlignmentLeft];
    self.textL.numberOfLines = 0;
    [contentView addSubview:self.textL];
    [self.textL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleL.mas_bottom).offset(4);
        make.left.offset(20);
        make.right.offset(-20);
    }];
    
    
    QMUILabel *ruleTitleL = [BRToolsView br_label:Localized(@"invite_howWorks") textColor:kColorTitle font:[UIFont br_fontB:15]];
   
    NSString *ruleText = Localized(@"invite_worksRule");
    QMUILabel *ruleTextL = [BRToolsView br_label:ruleText textColor:kColorTitle font:[UIFont br_fontR:14]];
    ruleTextL.attributedText = [BRStringTools br_attLineSpace:6 text:ruleText range:NSMakeRange(0, ruleText.length)];
    
    QMUILabel *readL = [BRToolsView br_label:Localized(@"invite_readInvite") textColor:kColorTitle font:[UIFont br_fontS:14]];
    
    ruleTitleL.numberOfLines = 0;
    ruleTextL.numberOfLines = 0;
    readL.numberOfLines = 0;
    
    
    [contentView addSubview:ruleTitleL];
    [ruleTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.textL.mas_bottom).offset(10);
        make.left.offset(20);
        make.right.offset(-20);
    }];
    [contentView addSubview:ruleTextL];
    [ruleTextL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(ruleTitleL.mas_bottom).offset(4);
        make.left.offset(20);
        make.right.offset(-20);
    }];
    [contentView addSubview:readL];
    [readL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(ruleTextL.mas_bottom).offset(10);
        make.left.offset(20);
        make.right.offset(-20);
    }];
    
//
//    UIStackView *stackView = [[UIStackView alloc] init];
//    stackView.alignment = UIStackViewAlignmentFill;
//    stackView.distribution = UIStackViewDistributionFillEqually;
//    stackView.spacing = 0;
//    [contentView addSubview:stackView];//104(85) + 64
//    [stackView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.textL.mas_bottom).offset(4);
//        make.centerX.offset(0);
//        make.width.mas_equalTo(300);
//    }];
//    NSArray *titles = @[Localized(@"points_points"),Localized(@"menu_coupon")];
//    NSArray *imgs = @[@"invite_points",@"invite_coupon"];
//    for (int i = 0; i < titles.count; i++) {
//        
//        BRInviteTopImgView *itemV = [[BRInviteTopImgView alloc] initWithImg:imgs[i] title:titles[i]];
//        [stackView addArrangedSubview:itemV];
//        itemV.userInteractionEnabled = YES;
//        itemV.tag = 1000 + i;
//    }
}

- (void)br_text:(NSString *)text hidden:(BOOL)hidden by:(NSInteger)index {
    BRInviteTopImgView *item = [self viewWithTag:1000 + index];
    item.titleStr = text;
    item.hidden = hidden;
}



@end
